package vip.web3.admin.sys.mapper;

import java.util.Date;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import org.springframework.util.CollectionUtils;
import vip.web3.admin.sys.vo.biz.BizUserWalletVo;
import vip.web3.admin.sys.vo.biz.UserWalletVo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Mapper
public interface AUserWalletMapper {

    AUserWalletMapper INSTANCE = Mappers.getMapper(AUserWalletMapper.class);

    @Mapping(target = "amountCny", ignore = true)
    @Mapping(target = "amountUsdt", ignore = true)
    @Mapping(target = "withdrawCny", ignore = true)
    @Mapping(target = "withdrawUsdt", ignore = true)
    BizUserWalletVo toBizUserWalletVo(UserWalletVo vo);

    default BizUserWalletVo toAdminBizUserWalletVo(UserWalletVo vo) {
        BizUserWalletVo walletVo = toBizUserWalletVo(vo);

        if (Objects.nonNull(walletVo) && Objects.nonNull(vo)) {

            BigDecimal amountCny = Objects.isNull(vo.getAmountCny()) ? BigDecimal.ZERO : vo.getAmountCny();
            BigDecimal amountUsdt = Objects.isNull(vo.getAmountUsdt()) ? BigDecimal.ZERO : vo.getAmountUsdt();
            BigDecimal withdrawCny = Objects.isNull(vo.getWithdrawCny()) ? BigDecimal.ZERO : vo.getWithdrawCny();
            BigDecimal withdrawUsdt = Objects.isNull(vo.getWithdrawUsdt()) ? BigDecimal.ZERO : vo.getWithdrawUsdt();
            walletVo.setAmountCny(amountCny.stripTrailingZeros().toPlainString());
            walletVo.setAmountUsdt(amountUsdt.stripTrailingZeros().toPlainString());
            walletVo.setWithdrawCny(withdrawCny.stripTrailingZeros().toPlainString());
            walletVo.setWithdrawUsdt(withdrawUsdt.stripTrailingZeros().toPlainString());
        }
        return walletVo;
    }

    default List<BizUserWalletVo> toAdminBizUserWalletVoList(List<UserWalletVo> vos) {
        if (CollectionUtils.isEmpty(vos)) {
            return null;
        }

        List<BizUserWalletVo> list = new ArrayList<>(vos.size());
        for (UserWalletVo vo : vos) {
            list.add(this.toAdminBizUserWalletVo(vo));
        }

        return list;
    }
}
